const Mock = require('mockjs')

let dataList = {}

const mockImages = [
  Mock.mock('@image(750x350, @color)'),
  Mock.mock('@image(750x480, @color)'),
  Mock.mock('@image(750x640, @color)'),
  Mock.mock('@image(750x750, @color)'),
  Mock.mock('@image(750x1000, @color)')
]

const mockArea = Mock.mock({
  'result|6-10': [{
    'id|+1': 1,
    'region': '@region'
  }]
})

mockArea.result.map(async item => {
  let list = await generateList(item.region)
  list.region = item.region
  list.province.map(async province => {
    province['cities'] = await getCities().result
    if (province['cities'] && province['cities'].length) {
      province.cities.map(async city => {
        city['detail'] = await getDetail(item.region, province.name, city.city)
      })
    }
  })
  dataList[item.id] = list
})

function generateList (region) {
  return Mock.mock({
    'province|4-20': [{
      'id': '@increment',
      'image': '@image(750x350, @color)',
      'name': '@province()'
    }]
  })
}

function getCities () {
  return Mock.mock({
    'result|3-7': [{
      'id': '@id',
      'banner': '@image(750x350, @color)',
      'city': '@city()',
    }]
  })
}

function getDetail(region, province, city) {
  return Mock.mock({
    'region': region,
    'province': province,
    'city': city,
    'desc': '@cparagraph(2, 5)',
    'images|2-7': ['@image(750x480, @color)'],
    'detail': Mock.Random.pick(mockImages, 2, 4)
  })
}

module.exports = dataList
